﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cadbom
{
    public partial class MaterialPropertyForm : Form
    {
        DataTable dtBand = null;
        List<MrpProductBomMaterialProperty> propertys = null;
        Action<int,List<String>> callback = null;
        public MaterialPropertyForm(Action<int,List<String>> callback) 
        {
            this.callback = callback;
            InitializeComponent();
        }

        private void MaterialPropertyForm_Load(object sender, EventArgs e)
        {

        }
        public void initGridviewData(List<MrpProductBomMaterialProperty> propertys)
        {
            this.propertys = propertys;
            dtBand = new System.Data.DataTable();
            dtBand.Columns.Add("name");
            dtBand.Columns.Add("propertyType");
            dtBand.Columns.Add("drawingType");
            dtBand.Columns.Add("label");
            dtBand.Columns.Add("redius");
            dtBand.Columns.Add("color");
            dtBand.Columns.Add("id");
            dtBand.Columns.Add("handleId");
            foreach (MrpProductBomMaterialProperty property in propertys)
            {
                DataRow dr = dtBand.NewRow();
                dr["name"] = property.name;
                dr["propertyType"] = property.propertyType;
                dr["drawingType"] = property.drawingType;
                dr["label"] = property.label;
                dr["redius"] = property.redius;
                dr["color"] = property.color;
                dr["id"] = property.id;
                dr["handleId"] = property.handleId;
                dtBand.Rows.Add(dr);
            }
            this.dataGridView1.DataSource = dtBand;
            dataGridView1.Columns["name"].HeaderText = "名称";
            dataGridView1.Columns["propertyType"].HeaderText = "特征类型";
            dataGridView1.Columns["drawingType"].HeaderText = "图形类型";
            dataGridView1.Columns["label"].HeaderText = "特征标签";
            dataGridView1.Columns["redius"].HeaderText = "半径";
            dataGridView1.Columns["color"].HeaderText = "颜色";
            dataGridView1.Columns["id"].Visible = false;
            dataGridView1.Columns["handleId"].Visible = false;
            foreach (DataGridViewColumn item in dataGridView1.Columns) item.SortMode = DataGridViewColumnSortMode.NotSortable;

        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
            SetObject setObject = new SetObject();
            setObject.SelectAndLabel(this.propertys,callback);

        }

        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
                            using
                (SolidBrush b =
                new
                SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor))
            {

                string
                linenum = e.RowIndex.ToString();
                int
                linen = 0;
                linen = Convert.ToInt32(linenum) + 1;
                string
                line = linen.ToString();
                e.Graphics.DrawString(line, e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 5);
                SolidBrush B =
                new
                SolidBrush(Color.Red);
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
